#-*- coding: utf-8 -*-
'''
Created on 2016年8月16日

@author: huanghaoyu
'''

from xlrd import open_workbook

class ExcelReader(object):
    '''
    Read microsoft excel file.
    '''

    def __init__(self, excel_file = None):
        if excel_file is not None:
            self.open_excel(excel_file)

    def open_excel(self, excel_file):
        self.data = open_workbook(excel_file)
    
    def get_row_num_by_name(self, sheet_name):
        table = self.data.sheet_by_name(sheet_name)
        return table.nrows
    
    def get_col_num_by_name(self, sheet_name):
        table = self.data.sheet_by_name(sheet_name)
        return table.ncols
    
    def get_cell_value_by_name(self, sheet_name, row_index, col_index):
        table = self.data.sheet_by_name(sheet_name)
        cell_value = table.cell(row_index, col_index).value
        return cell_value
    
    def get_row_num_by_index(self, sheet_index):
        table = self.data.sheet_by_index(sheet_index)
        return table.nrows
    
    def get_col_num_by_index(self, sheet_index):
        table = self.data.sheet_by_index(sheet_index)
        return table.ncols
        
    def get_cell_value_by_index(self, sheet_index, row_index, col_index):
        table = self.data.sheet_by_index(sheet_index)
        cell_value = table.cell(row_index, col_index).value
        return cell_value
        
    
    